#pragma once

#undef KEY
#undef BUFLEN
template <unsigned int XORSTART, unsigned int BUFLEN, unsigned int XREFKILLER>
class XorStr
{
	private: 
		 XorStr();
	public: 
		char s[BUFLEN];

		 XorStr(const char* xs);
#ifndef DEBUG_OPTION
		 ~XorStr(){ for(unsigned int i=0;i<BUFLEN;i++)s[i]=0;} 
#endif
};
template <unsigned int XORSTART, unsigned int BUFLEN, unsigned int XREFKILLER>
XorStr<XORSTART,BUFLEN,XREFKILLER>::XorStr(const char* xs)
{
	const char *pOgi = xs-XREFKILLER;
	//printf("XorStr<0x%08X,%u,0x%08X>=0x%X\n",XORSTART,BUFLEN,XREFKILLER,pOgi);
	unsigned int xvalue = XORSTART;
	unsigned int i = 0;
	for(;i<(BUFLEN-1);i++) {
		//s[i] = xs[i-XREFKILLER]^xvalue;
		//s[i] = xs[i]^xvalue;
		s[i] = pOgi[i]^xvalue;
		xvalue += 1;
		xvalue %= 256;
	}
	s[BUFLEN-1] = 0;
}
